package lockmanager;


public class TestMain {

	
	/**
	 * Testing main
	 */
	public static void main(String[] args) {
	

		ResourcePool resPoolNonBlocking = new ResourcePoolNonBlocking();
		ResourcePool resPoolBlocking = new ResourcePoolBlocking();
		
	
		
		for(int i=0;i<300;i++){
			String name = "Thread"+i;
			TestThread test = new TestThread(name,resPoolBlocking);
			Thread th = new Thread(test);
			th.start();
		}
		
		while(!TestThread.finishedThreadNumber.compareAndSet(300, 300)){
			try {
				Thread.sleep(300);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		Long avgTime = 0L;
		Long times = 0L;
		for (Long time : TestThread.getresults){
			times++;
			avgTime += time;
		}
		System.out.println("AVG Get Time: "+avgTime/times);
		
		avgTime = 0L;
		times = 0L;
		for (Long time : TestThread.putresults){
			times++;
			avgTime += time;
		}
		System.out.println("AVG Put Time: "+avgTime/times);
		
		System.out.println("Total Started Thread: "+ TestThread.startedThreadNumber.get());
		
		System.out.println("Total finished Thread: " +TestThread.finishedThreadNumber.get());
		

	}

}
